// 引入 Mock
import { options } from 'less'
import Mock from 'mockjs'

// 定义数据类型
let { data } = Mock.mock({
  // 20条数据
  'data|70': [
    {
      //id
      'id|+1': 1,
      name: '@cname',
      // 商品种类
      goodsClass: '女装',
      // 商品Id
      'goodsId|+1': 1,
      //商品名称
      goodsName: '@ctitle(10)',
      //商品地址
      goodsAddress: '@county(true)',
      //商品等级评价★
      'goodsStar|1-5': '★',
      //商品图片
      goodsImg: "@Image('100x100','@color','小甜甜')",
      //商品售价
      'goodsSale|30-500': 30,
    },
  ],
})

//分页
Mock.mock('/api/list', 'post', (option) => {
  const { currentPage, pageSize } = JSON.parse(option.body)

  //截取的数据
  const result = data.slice((currentPage - 1) * pageSize, currentPage * pageSize)
  return {
    result: result,
    status: 0,
    //总数
    total: data.length,
  }
})

//删除的接口
Mock.mock('/api/remove', 'post', (option) => {
  const { id } = JSON.parse(option.body)

  data = data.filter((item) => item.id !== id)

  return {
    status: 0,
    msg: '删除成功',
  }
})

export default Mock
